﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.ComponentModel;

namespace Common.Expansion
{
    public static class EnumEx
    {
        public static string GetDescription(this Enum e)
        {
            string value = e.ToString();

            FieldInfo field = e.GetType().GetField(value);

            if (field != null)
            {
                Object[] objs = field.GetCustomAttributes(typeof(DescriptionAttribute), false);
                if (objs == null || objs.Length == 0)
                    return value;
                else
                    return ((DescriptionAttribute)objs[0]).Description;
            }
            else
                return "";
        }

    }
}
